//
//  EXT+UIImage.swift
//  WB25
//
//  Created by HM on 2017/6/29.
//  Copyright © 2017年 itheima. All rights reserved.
//

import UIKit
/*
    - 通过代码方式来解决图片拉伸问题
 */
extension UIImage {
    // 通过class 来修饰类方法
    class func resizableImage(named:String) -> UIImage{
        // 图片
        let image = UIImage(named: named)!
        // 设置端盖的值
        let top = image.size.height * 0.5
        let left = image.size.width * 0.5
        let bottom = image.size.height * 0.5
        let right = image.size.width * 0.5
        let edgeInsets =  UIEdgeInsetsMake(top, left, bottom, right)
        // 拉伸图片
        let newImage = image.resizableImage(withCapInsets: edgeInsets)
        return newImage
    }
}
